import net.spreadshirt.util.Observer;
import net.spreadshirt.util.Observable;
import net.spreadshirt.logger.Logger;
import net.spreadshirt.logger.LogMessage;

/**
 * An observer of the Logger class. This class displays
 * messages sent to the log in an on-screen text field.
 */
class net.spreadshirt.logger.TextAreaView implements Observer {

	// The log that this object is observing.
	private var log:net.spreadshirt.logger.Logger;

	// A reference to the text field.
	private var out:TextField;

	/**
	 * TextFieldView Constructor
	 */
	public function TextAreaView(l:Logger, tf:TextField) {
		log = l;
		out = tf;
	}

	/**
	 * Invoked when the log changes. For details, see the
	 * Observer interface.
	 */
	public function update(o:Observable, infoObj:Object):Void {
		// Cast infoObj to a LogMessage instance for type checking.
		var logMsg:LogMessage = LogMessage(infoObj);
		// Display the log message in the log text field.
		out.text += Logger.getLevelDesc(logMsg.getLevel()) +": "
			+ logMsg.getMessage() +"\n";
	}

}
